<?php
abstract class GaAPI_Objects_Common_Object {

    protected $_fields = array();

    public function  __construct() {
    }

    public function  __call($name,  $arguments) {
        $this->throwError('Invalid method call [' . $name . ']');
    }

    public function setFromArray($array) {
        if (is_array($array)) {
            foreach ($array as $param => $value) {
                $this->$param = $value;
            }
        }
        return $this;
    }
    
    public function setApi($api) {
        $this->_api = $api;
    }

    public function getApi() {
        return $this->_api;
    }
    
    public function getFields() {
        return $this->_fields;
    }

    public function  __toString() {
        $xml = '';

        $xml .= $this->startString();
        $fields = $this->getFields();
        foreach ($fields as $field) {
            $xml .= ($this->$field) ? '<' . $field . '>' . $this->$field . '</' . $field. '>' : '';
        }

        $xml .= $this->endString();
        return $xml;
    }

    protected function startString() {
        return '';
    }
    
    protected function endString() {
        return '';
    }

    protected function throwError($error_msg) {
        $this->getApi()->throwError($error_msg);
    }

}